// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

import Vue from "vue";
import App from "./App";
import router from "./router";
import "babel-polyfill";
import axios from "axios";
import "lib-flexible/flexible.js";
import VueSlider from "vue-slider-component";
import "vue-slider-component/theme/default.css";
import json from "../static/config.json";
import Vant, { Notify } from "vant";

import "@/assets/css/mycss.css";
import "vant/lib/index.css";
// import Vconsole from "vconsole";
Vue.use(Vant);

Vue.component("VueSlider", VueSlider);
Vue.config.productionTip = false;
axios.defaults.withCredentials = true;
const ENV = process.env;
// Vue.prototype.$Vconsole = new Vconsole();
Vue.prototype.masterUrl = json.masterUrl;
console.log(ENV);
// var _hmt = _hmt || [];
// window._hmt = _hmt;
// (function () {
//   var hm = document.createElement("script");
//   hm.src = "https://hm.baidu.com/hm.js?58cb24b2531f6a14e56080ed7b20b983";
//   var s = document.getElementsByTagName("script")[0];
//   s.parentNode.insertBefore(hm, s);
// })();
// test 环境
if (ENV.NODE_ENV === "production" && ENV.EVN_CONFIG === "test") {
  axios.defaults.baseURL = "https://www.zsrencai.cn";
} else if (ENV.NODE_ENV === "production" && ENV.EVN_CONFIG === "prod") {
  // 生产环境地址
  axios.defaults.baseURL = "https://www.zsrencai.cn";
} else if (ENV.NODE_ENV === "production" && ENV.EVN_CONFIG === "pre") {
  // 开发环境地址
  axios.defaults.baseURL = "https://www.zsrencai.cn";
} else if (ENV.NODE_ENV === "production" && ENV.EVN_CONFIG === "sim") {
  // 仿真境地址
  axios.defaults.baseURL = "https://www.zsrencai.cn";
} else {
  axios.defaults.baseURL = "https://www.zsrencai.cn";
}

axios.interceptors.request.use(
  config => {
    if (!navigator.onLine) {
      Notify({
        message: "网络未连接"
      });
    } else {
      Notify.clear();
    }
    console.log(localStorage.getItem("ad_Authorization"), "ad_Authorization");
    let token = localStorage.getItem("token");
    // if (sessionStorage.getItem('token')) {
    //   token = sessionStorage.getItem('token')
    //   config.headers.Authorization = 'Bearer ' + token
    // } else {
    //   token = localStorage.getItem('ad_Authorization')
    //   config.headers.token = 'Bearer ' + token
    // }

    if (token) {
      config.headers.Authorization = "Bearer " + token;
    }

    return config;
  },
  err => {
    console.log(err);
    return Promise.reject(err);
  }
);
// router.beforeEach((to, from, next) => {
//   if (window._hmt) {
//     if (to.path) {
//       window._hmt.push(['_trackPageview', '/#' + to.fullPath])
//     }
//   }
//   next()
// })
/* eslint-disable no-new */
new Vue({
  el: "#app",
  router,
  components: { App },
  template: "<App/>"
});
